﻿var keyValue = request('keyValue');
var flxh = request('flxh');
var companyId = request('companyId');
var ztId = request('ztId');
var kjnd = request('kjnd');
var kjqj = request('kjqj');
var userId = request('userId');
var fileList;

var preRowIndex = -1;
var preKmObj = new Object();
var pageWidth = 1024;
var userdefault = {};
var page;
var edit = 0;
var hasInitTree = false;
var copyFlRowData;
var copyExtRowData;

$(function () {
    if (!!window.bootstrap) {
        bootstrap(jQuery, top.learun);
    }
});

var bootstrap = function ($, learun) {
    "use strict";
    page = {
        init: function () {
            userdefault = learun.clientdata.get(['usersetting']);
            //初始化打印插件
            hiprint.init();
            page.bind();
            page.InitData();
        },

        bind: function () {
            pageWidth = ($('.gridPanel').width());

            $('#gridTable').setGridWidth(($('.gridPanel').width()) - 30);
            $(".bills").height($(window).height() - 25);
            $("#lr_layout").height($(window).height() - 22);

            page.InitControl();
            page.InitialPage();
            page.InitPzflGrid();
            page.InitPzflextGrid();
        },

        InitialPage: function () {
            var pzrq = $("#pzrq").val();
            //初始化凭证日期
            if(!pzrq){
                var y = userdefault.kjnd;
                var m = new Date().getMonth() + 1;
                if(!!kjqj){
                    m = kjqj;
                }
                if (m < 10) {
                    m = '0' + m;
                }
                var d = new Date().getDate();
                pzrq = y + "-" + m + "-" + d;
                $("#pzrq").val(pzrq);
            }

            //获取凭证号
            setDatePickerValue(pzrq);
//            //财务主管
//            $.ajax({
//                url: config.base_server() + 'kjnds/findByKjnd?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&access_token=' + config.getToken().access_token,
//                type: "get",
//                dataType: "json",
//                async: false,
//                success: function (result) {
//                    if (result != null) {
//                        $("#cwzg").val(result.data.cwzg);
//                        $("#zdy").val(result.data.kjy);
//                    }
//                }
//            });
        },

        InitControl: function () {//初始化控件
            //凭证类型
            $('#pzlxCode').lrDataItemSelect({
                code: 'PZLXS', maxHeight: 100,placeholder: "==请选择凭证类型==",
                select: function (item) {

                }
            }).lrselectSetFirst();

            //刷新凭证列表
            $('#btn_refresh').on('click', function () {
                page.InitTree();
            });
        },

        //加载凭证表
        InitPzflGrid: function () {
            var $grid = $("#gridTable");
            $grid.jqGrid({
                unwritten: false,
                datatype: "local",
                height: '250',
                autowidth: true,
                colModel: [
                    {label: '主键', name: 'flid', hidden: true},
                    {label: 'extList', name: 'extList', hidden: true},
                    {label: '是否部门核算', name: 'isDepartmentHs', hidden: true},
                    {label: '是否项目核算', name: 'isProjectHs', hidden: true},
                    {label: '是否经济分类核算', name: 'isExpecoHs', hidden: true},
                    {label: '是否支出功能分类核算', name: 'isExpfuncHs', hidden: true},
                    {label: '是否预算项目核算', name: 'isDepproHs', hidden: true},
                    {label: '摘要',name: "zy",width: (pageWidth * (40 / 100)),align: 'center',sortable: false,resizable: false},
                    {label: '会计科目',name: "kjkmName1",width: (pageWidth * (40 / 100)),align: 'center',sortable: false,resizable: false},
                    {label: '借方金额',name: 'j1',width: (pageWidth * (20 / 100)),align: 'center',sortable: false,resizable: false},
                    {label: '贷方金额',name: 'd1',width: (pageWidth * (20 / 100)),align: 'center',sortable: false,resizable: false},
                    {label: '会计科目',name: "kjkmName2",width: (pageWidth * (40 / 100)),align: 'center',sortable: false,resizable: false},
                    {label: '借方金额',name: 'j2',width: (pageWidth * (20 / 100)),align: 'center',sortable: false,resizable: false},
                    {label: '贷方金额',name: 'd2',width: (pageWidth * (20 / 100)),align: 'center',sortable: false,resizable: false},
                    {label: '科目Code', name: 'kjkmCode1', hidden: true},
                    {label: '科目Code', name: 'kjkmCode2', hidden: true}
                ],
                pager: false,
                rownumbers: true,
                rowNum: 2000,
                shrinkToFit: true,
                gridview: true,
                footerrow: true,
                scroll: true,

                gridComplete: function () {
                    //合计
                    $(this).footerData("set", {
                        "zy": "合计：",
                        "j1": "<span id='TotalJ1'>0.00</span>",
                        "d1": "<span id='TotalD1'>0.00</span>",
                        "j2": "<span id='TotalJ2'>0.00</span>",
                        "d2": "<span id='TotalD2'>0.00</span>",
                    });
                    $('table.ui-jqgrid-ftable td[aria-describedby="gridTable_kjkmName"]').prevUntil().css("border-right-color", "#FFFDCD");
                },
                beforeSelectRow: function (rowid, e) {
                    var row = $grid.jqGrid('getRowData', rowid);

                    $grid.find('tr[id="'+rowid+'"]').addClass("selectrow");
                    $grid.find('tr[id!="'+rowid+'"]').removeClass("selectrow");

                    if (rowid > 1 && $(row.j).attr("readonly") != "readonly") {
                        var preZy = "";
                        $grid.find('[role=row]').each(function (i) {
                            if (i == 0) {
                                return true;
                            }
                            if (i == (rowid - 1)) {
                                preZy = $(this).find('input[name="zy"]').val();
                            }
                            if (i == rowid) {
                                if ($(this).find('input[name="zy"]').val() == "") {
//                                    $(this).find('input[name="zy"]').val(preZy);
                                }
                                return false;
                            }
                        });
                    }

                    if (preRowIndex == rowid) {
                        preRowIndex = rowid;
                        return;
                    }

                    //存储extGrid录入的数据
                    page.saveExtGridData();

                    preKmObj.isDepartmentHs = $(row.isDepartmentHs).val();
                    preKmObj.isProjectHs = $(row.isProjectHs).val();
                    preKmObj.isExpecoHs = $(row.isExpecoHs).val();
                    preKmObj.isExpfuncHs = $(row.isExpfuncHs).val();
                    preKmObj.isDepproHs = $(row.isDepproHs).val();

                    $("#gridTable_ext").find('[role=row]').each(function (i) {
                        $(this).find('input[name="extid"]').val("");
                        $(this).find('input[name="departmentName"]').val("");
                        $(this).find('input[name="projectName"]').val("");
                        $(this).find('input[name="depproName"]').val("");
                        $(this).find('input[name="expecoName"]').val("");
                        $(this).find('input[name="expfuncName"]').val("");
                        $(this).find('input[name="j1"]').val("");
                        $(this).find('input[name="d1"]').val("");
                        $(this).find('input[name="j2"]').val("");
                        $(this).find('input[name="d2"]').val("");
                        $(this).find('input[name="departmentCode"]').val("");
                        $(this).find('input[name="projectCode"]').val("");
                        $(this).find('input[name="depproCode"]').val("");
                        $(this).find('input[name="expecoCode"]').val("");
                        $(this).find('input[name="expfuncCode"]').val("");
                    });
                    preRowIndex = rowid;
                    if (preKmObj.isExpecoHs == 0 && preKmObj.isExpfuncHs == 0 && preKmObj.isDepproHs == 0 && preKmObj.isProjectHs == 0 && preKmObj.isDepartmentHs == 0) {
                        $("#gbox_gridTable_ext").hide();
                    } else {
                        page.GetPzflextGrid(preKmObj);
                        var extLists = eval("(" + row.extList + ")");
                        var $grid_ext = $("#gridTable_ext");
                        $grid_ext.jqGrid('clearGridData');
                        var rowdatas = [];
                        var rowCount =  $grid_ext.jqGrid('getGridParam', 'records');
                        if (extLists.length > rowCount) {
                            //默认添加7行 空行
                            for (var i = rowCount + 1; i < extLists.length + 1; i++) {
                                var rowdata = {
                                    extid: '<input name="extid" type="hidden" />',
                                    expfuncName: '<div class="product"><input name="expfuncName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_dept"></span></div>',
                                    expecoName: '<div class="product"><input name="expecoName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_xm"></span></div>',
                                    depproName: '<div class="product"><input name="depproName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_ajh"></span></div>',
                                    projectName: '<div class="product"><input name="projectName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_pjh"></span></div>',
                                    departmentName: '<div class="product"><input name="departmentName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_zph"></span></div>',
                                    j: '<input name="j" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                                    d: '<input name="d" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                                    expfuncCode: '<input name="expfuncCode" type="hidden" />',
                                    expecoCode: '<input name="expecoCode" type="hidden" />',
                                    depproCode: '<input name="depproCode" type="hidden" />',
                                    projectCode: '<input name="projectCode" type="hidden" />',
                                    departmentCode: '<input name="departmentCode" type="hidden" />',

                                    extxh: i
                                }
                                //$grid_ext.jqGrid('addRowData', i, rowdata);
                                rowdatas.push(rowdata);  //TODO 判断当前表格多少行，而不是从5，多次进入可能重复添加行
                            }
                            if (rowdatas.length > 0) {
                                $grid_ext.jqGrid('addRowData', 'extxh', rowdatas);
                                page.propGridExt();
                            }
                        }
                        if(extLists.length==0){ //为空则默认加个空行
                            var rowdata = {
                                extid: '<input name="extid" type="hidden" />',
                                expfuncName: '<div class="product"><input name="expfuncName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_dept"></span></div>',
                                expecoName: '<div class="product"><input name="expecoName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_xm"></span></div>',
                                depproName: '<div class="product"><input name="depproName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_ajh"></span></div>',
                                projectName: '<div class="product"><input name="projectName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_pjh"></span></div>',
                                departmentName: '<div class="product"><input name="departmentName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_zph"></span></div>',
                                j: '<input name="j" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                                d: '<input name="d" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                                expfuncCode: '<input name="expfuncCode" type="hidden" />',
                                expecoCode: '<input name="expecoCode" type="hidden" />',
                                depproCode: '<input name="depproCode" type="hidden" />',
                                projectCode: '<input name="projectCode" type="hidden" />',
                                departmentCode: '<input name="departmentCode" type="hidden" />',
                                extxh: 1
                            }
                            $grid_ext.jqGrid('addRowData', i, rowdata);
                            page.propGridExt();
                        }
                        $("#gridTable_ext").find('[role=row]').each(function (i) {
                            var row = extLists[i - 1];
                            if (row != undefined) {
                                $(this).find('input[name="extid"]').val(row.extid);
                                $(this).find('input[name="expfuncName"]').val(row.expfuncName);
                                $(this).find('input[name="expecoName"]').val(row.expecoName);
                                $(this).find('input[name="depproName"]').val(row.depproName);
                                $(this).find('input[name="projectName"]').val(row.projectName);
                                $(this).find('input[name="departmentName"]').val(row.departmentName);

                                var jj = $.formatMoney(row.j, 2);
                                var dd = $.formatMoney(row.d, 2);
                                if (jj != "0.00") {
                                    $(this).find('input[name="j"]').val(jj);
                                }
                                if (dd != "0.00") {
                                    $(this).find('input[name="d"]').val(dd);
                                }
                                $(this).find('input[name="expfuncCode"]').val(row.expfuncCode);
                                $(this).find('input[name="expecoCode"]').val(row.expecoCode);
                                $(this).find('input[name="depproCode"]').val(row.depproCode);
                                $(this).find('input[name="projectCode"]').val(row.projectCode);
                                $(this).find('input[name="departmentCode"]').val(row.departmentCode);

                                //$(this).find('input').removeAttr('disabled').attr("isvalid", "yes");
                                $(this).find('input').removeAttr('disabled');//删除
                                $(this).next().find('input').removeAttr('disabled');
                            }
                        });

                        totalCalcExt();

                        $("#gbox_gridTable_ext").show();
                        //默认不可编辑
                        if (edit == 0) {
                            $("#form1 input").attr("readonly", "readonly");
                        } else {
                            $("#gridTable").find('[role=row][id="'+rowid+'"]').each(function (i) {
                                $(this).find('input[name="j"]').attr("disabled", "disabled");
                                $(this).find('input[name="d"]').attr("disabled", "disabled");
                            });
                        }
                    }
                }
            });

            $("#gridTable").jqGrid('setGroupHeaders', {
                useColSpanStyle :  true , // 没有表头的列是否与表头列位置的空单元格合并
                groupHeaders :[{
                        startColumnName :"kjkmName1", //开始列
                        numberOfColumns : 3, //合并几列
                        titleText : "财务会计",//合并后父列名
                        },
                        {
                        startColumnName : "kjkmName2", //开始列
                        numberOfColumns : 3, //合并几列
                        titleText :"预算会计" //合并后父列名
                    }]
            });

            //默认添加7行 空行
            for (var i = 1; i < 8; i++) {
                var rowdata = {
                    flid: '<input name="flid" type="hidden" />',
                    extList: [],
                    isDepartmentHs: '<input name="isDepartmentHs" type="hidden" value="0"/>',
                    isProjectHs: '<input name="isProjectHs" type="hidden" value="0"/>',
                    isExpecoHs: '<input name="isExpecoHs" type="hidden" value="0"/>',
                    isExpfuncHs: '<input name="isExpfuncHs" type="hidden" value="0"/>',
                    isDepproHs: '<input name="isDepproHs" type="hidden" value="0"/>',
                    zy: '<div class="product"><input name="zy"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_zy"></span></div>',
                    kjkmName1: '<div class="product"><input name="kjkmName1"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_kjkm"></span></div>',
                    j1: '<input name="j1" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                    d1: '<input name="d1" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                    kjkmName2: '<div class="product"><input name="kjkmName2"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_kjkm"></span></div>',
                    j2: '<input name="j2" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                    d2: '<input name="d2" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                    kjkmCode1: '<input name="kjkmCode1" type="hidden"/>',
                    kjkmCode2: '<input name="kjkmCode2" type="hidden"/>',
                    flxh: i
                }
                $grid.jqGrid('addRowData', i, rowdata);
            }
        },

        //加载凭证辅助表
        GetPzflextGrid: function (kmJsonData) {
            var $grid_ext = $("#gridTable_ext");

            if (kmJsonData.isDepartmentHs == 1) {
                $grid_ext.setGridParam().showCol("departmentName").trigger("reloadGrid");
            } else {
                $grid_ext.setGridParam().hideCol("departmentName").trigger("reloadGrid");
            }
            if (kmJsonData.isProjectHs == 1) {
                $grid_ext.setGridParam().showCol("projectName").trigger("reloadGrid");
            } else {
                $grid_ext.setGridParam().hideCol("projectName").trigger("reloadGrid");
            }
            if (kmJsonData.isExpecoHs == 1) {
                $grid_ext.setGridParam().showCol("expecoName").trigger("reloadGrid");
            } else {
                $grid_ext.setGridParam().hideCol("expecoName").trigger("reloadGrid");
            }
            if (kmJsonData.isExpfuncHs == 1) {
                $grid_ext.setGridParam().showCol("expfuncName").trigger("reloadGrid");
            } else {
                $grid_ext.setGridParam().hideCol("expfuncName").trigger("reloadGrid");
            }
            if (kmJsonData.isDepproHs == 1) {
                $grid_ext.setGridParam().showCol("depproName").trigger("reloadGrid");
            } else {
                $grid_ext.setGridParam().hideCol("depproName").trigger("reloadGrid");
            }

            page.propGridExt();
        },

        //初始化分录明细表
        InitPzflextGrid: function () {
            var $grid_ext = $("#gridTable_ext");
            // $grid.jqGrid('GridUnload');
            $grid_ext.jqGrid({
                unwritten: false,
                datatype: "local",
                height: '200',
                autowidth: true,
                colModel: [
                    {label: '主键', name: 'extid', hidden: true},
                    {label: '支出功能分类', name: "expfuncName", width: 250, align: 'center', sortable: false, resizable: false},
                    {label: '部门经济分类', name: "expecoName", width: 250, align: 'center', sortable: false, resizable: false},
                    {label: '预算项目', name: "depproName", width: 250, align: 'center', sortable: false, resizable: false},
                    {label: '项目', name: "projectName", width: 250, align: 'center', sortable: false, resizable: false},
                    {label: '部门', name: "departmentName", width: 250, align: 'center', sortable: false, resizable: false},
                    {label: '借方额',name: 'j',width: 130,align: 'center',sortable: false,resizable: false,fixed: true},
                    {label: '贷方额',name: 'd',width: 130,align: 'center',sortable: false,resizable: false,fixed: true},
                    {label: '支出功能分类', name: 'expfuncCode', hidden: true},
                    {label: '部门经济分类', name: 'expecoCode', hidden: true},
                    {label: '预算项目', name: 'depproCode', hidden: true},
                    {label: '项目', name: 'projectCode', hidden: true},
                    {label: '部门', name: 'departmentCode', hidden: true},
                    {label: '序号', name: 'extxh', hidden: true},

                ],
                pager: false,
                rownumbers: true,
                rowNum: 2000,
                shrinkToFit: false,
                gridview: true,
                footerrow: true,
                scroll: true,

                gridComplete: function () {
                    //合计
                    $(this).footerData("set", {
                        "expecoName": "合计：",
                        "j": "<span id='TotalExtJ'>0.00</span>",
                        "d": "<span id='TotalExtD'>0.00</span>",
                    });
                    $('table.ui-jqgrid-ftable td[aria-describedby="gridTable_bmName"]').prevUntil().css("border-right-color", "#fffdcd");
                }
            });

            $("#gbox_gridTable_ext").hide();
            //默认添加7行 空行
            for (var i = 1; i < 5; i++) {
                var rowdata = {
                    extid: '<input name="extid" type="hidden" />',
                    expfuncName: '<div class="product"><input name="expfuncName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_dept"></span></div>',
                    expecoName: '<div class="product"><input name="expecoName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_xm"></span></div>',
                    depproName: '<div class="product"><input name="depproName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_ajh"></span></div>',
                    projectName: '<div class="product"><input name="projectName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_pjh"></span></div>',
                    departmentName: '<div class="product"><input name="departmentName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_zph"></span></div>',
                    j: '<input name="j" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                    d: '<input name="d" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                    expfuncCode: '<input name="expfuncCode" type="hidden" />',
                    expecoCode: '<input name="expecoCode" type="hidden" />',
                    depproCode: '<input name="depproCode" type="hidden" />',
                    projectCode: '<input name="projectCode" type="hidden" />',
                    departmentCode: '<input name="departmentCode" type="hidden" />',
                    extxh: i
                }
                $grid_ext.jqGrid('addRowData', i, rowdata);
            }

            //$grid_ext.find('.decimal').attr('onfocus', 'IsMoney(this.id)');
            $grid_ext.find('input').attr("disabled", "disabled");
            // $grid_ext.find("tbody tr:eq(1)").find('input').removeAttr('disabled').attr("isvalid", "yes");
            //$grid_ext.find("tbody tr:eq(1)").find('input').removeAttr('disabled');//删除
            $grid_ext.find('.disabled').attr("disabled", "disabled");

            ////价格文本框事件
            //$grid_ext.find('.decimal').click(function () {
            //    $(this).select();
            //});
        },

        InitData: function () {
            var $grid = $("#gridTable");
            var $grid_ext = $("#gridTable_ext");
            //默认添加7行 空行
            $grid.jqGrid('clearGridData');
            $grid_ext.jqGrid('clearGridData');
            for (var i = 1; i < 8; i++) {
                var rowdata = {
                    flid: '<input name="flid" type="hidden" />',
                    extList: [],
                    isDepartmentHs: '<input name="isDepartmentHs" type="hidden" value="0"/>',
                    isProjectHs: '<input name="isProjectHs" type="hidden" value="0"/>',
                    isExpecoHs: '<input name="isExpecoHs" type="hidden" value="0"/>',
                    isExpfuncHs: '<input name="isExpfuncHs" type="hidden" value="0"/>',
                    isDepproHs: '<input name="isDepproHs" type="hidden" value="0"/>',
                    zy: '<div class="product"><input name="zy"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_zy"></span></div>',
                    kjkmName1: '<div class="product"><input name="kjkmName1"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_kjkm"></span></div>',
                    j1: '<input name="j1" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                    d1: '<input name="d1" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                    kjkmName2: '<div class="product"><input name="kjkmName2"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_kjkm"></span></div>',
                    j2: '<input name="j2" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                    d2: '<input name="d2" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                    kjkmCode1: '<input name="kjkmCode1" type="hidden"/>',
                    kjkmCode2: '<input name="kjkmCode2" type="hidden"/>',
                    flxh: i
                }
                $grid.jqGrid('addRowData', i, rowdata);
            }
            //默认添加7行 空行
            for (var i = 1; i < 5; i++) {
                var rowdata = {
                    extid: '<input name="extid" type="hidden" />',
                    expfuncName: '<div class="product"><input name="expfuncName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_dept"></span></div>',
                    expecoName: '<div class="product"><input name="expecoName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_xm"></span></div>',
                    depproName: '<div class="product"><input name="depproName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_ajh"></span></div>',
                    projectName: '<div class="product"><input name="projectName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_pjh"></span></div>',
                    departmentName: '<div class="product"><input name="departmentName"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_zph"></span></div>',
                    j: '<input name="j" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                    d: '<input name="d" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                    bmCode: '<input name="bmCode" type="hidden" />',
                    xmCode: '<input name="xmCode" type="hidden" />',
                    wldxCode: '<input name="wldxCode" type="hidden" />',
                    extxh: i
                }
                $grid_ext.jqGrid('addRowData', i, rowdata);
            }
            //获取表单
            if (!!keyValue) {
                $.SetForm({
                    url: config.base_server() + 'glvous/findById?id=' + keyValue + '&access_token=' + config.getToken().access_token,
                    param: {keyValue: keyValue},
                    success: function (result) {
                        //主表
                        var pz = result.data;
                        $("#form1").SetWebControls(pz);

                        $("#kjnd_select").lrselectSet(pz.kjnd);
                        kjqj = pz.kjqj;

                        $("#zdy").val(pz.zdy);
                        $("#shy").val(pz.shy);
                        $("#jzy").val(pz.jzy);
                        $("#cwzg").val(pz.cwzg);
                        $("#fj").val(pz.fj);
                        $("#pzrq").val(pz.pzrq.substring(0, 10));
                        $("#pzlxCode").val(pz.pzlxCode);
                        $("#pzh").val(pz.pzh);
                        $("#pzid").val(pz.pzid);
                        if (pz.isQc == 1) {
                            $("#isQc").attr("checked", "checked");
                        } else {
                            $("#isQc").removeAttr("checked");
                        }
                        if (pz.isJz == 1) {
                            $("#isJz").attr("checked", "checked");
                        } else {
                            $("#isJz").removeAttr("checked");
                        }
                        $("#isTemp").val(pz.isTemp);
                        //明细
                        var flEntry = pz.pzflList;
                        var rowCount = 8;
                        if (flEntry.length > 6) {
                            rowCount = parseInt(flEntry.length) + 1;
                        }
                        var rowdatas = [];
                        //默认添加7行 空行
                        for (var i = 8; i < rowCount; i++) {
                            var rowdata = {
                                flid: '<input name="flid" type="hidden" />',
                                extList: [],
                                isDepartmentHs: '<input name="isDepartmentHs" type="hidden" value="0"/>',
                                isProjectHs: '<input name="isProjectHs" type="hidden" value="0"/>',
                                isExpecoHs: '<input name="isExpecoHs" type="hidden" value="0"/>',
                                isExpfuncHs: '<input name="isExpfuncHs" type="hidden" value="0"/>',
                                isDepproHs: '<input name="isDepproHs" type="hidden" value="0"/>',
                                zy: '<div class="product"><input name="zy"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_zy"></span></div>',
                                kjkmName1: '<div class="product"><input name="kjkmName1"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_kjkm"></span></div>',
                                j1: '<input name="j1" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                                d1: '<input name="d1" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                                kjkmName2: '<div class="product"><input name="kjkmName2"  type="text" autocomplete="off" class="editable" isvalid="no" checkexpession="NotNull"/><span class="ui-icon-ellipsis ellipsis_kjkm"></span></div>',
                                j2: '<input name="j2" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                                d2: '<input name="d2" type="text" autocomplete="off" onblur="toMoney(this.value, this)" onfocus="toNumber(this.value, this)" class="editable center decimal" min="0" isvalid="no" checkexpession="Double" />',
                                kjkmCode1: '<input name="kjkmCode1" type="hidden"/>',
                                kjkmCode2: '<input name="kjkmCode2" type="hidden"/>',
                                flxh: i
                            }
                            //$grid.jqGrid('addRowData', i, rowdata);
                            rowdatas.push(rowdata);
                        }
                        if (rowdatas.length > 0) {
                            $grid.jqGrid('addRowData', 'flxh', rowdatas);
                        }

                        $("#gridTable").find('[role=row]').each(function (i) {
                            var row = flEntry[i - 1];
                            if (row != undefined) {
                                $(this).find('input[name="pzid"]').val(row.pzid);
                                $(this).find('input[name="flid"]').val(row.flid);
                                var extList = JSON.stringify(row.extList);
                                $(this).find('td[aria-describedby="gridTable_extList"]').text(extList);
                                $(this).find('input[name="zy"]').val(row.zy);
                                $(this).find('input[name="kjkmCode1"]').val(row.kjkmCode1);
                                $(this).find('input[name="kjkmName1"]').val(row.kjkmSimpleName1);
                                $(this).find('input[name="kjkmCode2"]').val(row.kjkmCode2);
                                $(this).find('input[name="kjkmName2"]').val(row.kjkmSimpleName2);
                                var jj1 = $.formatMoney(row.j1, 2);
                                var dd1 = $.formatMoney(row.d1, 2);
                                var jj2 = $.formatMoney(row.j2, 2);
                                var dd2 = $.formatMoney(row.d2, 2);
                                if (jj1 != "0.00") {
                                    $(this).find('input[name="j1"]').val(jj1);
                                }
                                if (dd1 != "0.00") {
                                    $(this).find('input[name="d1"]').val(dd1);
                                }
                                if (jj2 != "0.00") {
                                    $(this).find('input[name="j2"]').val(jj2);
                                }
                                if (dd2 != "0.00") {
                                    $(this).find('input[name="d2"]').val(dd2);
                                }
//                                if (jj == "0.00" && dd == "0.00") {
//                                    if (!!extList && extList.length > 0) {
//                                        if (extList[0].j != "0.00") {
//                                            $(this).find('input[name="j1"]').val(jj);
//                                            $(this).find('input[name="j2"]').val(jj);
//                                        } else {
//                                            $(this).find('input[name="d1"]').val(dd);
//                                            $(this).find('input[name="d2"]').val(dd);
//                                        }
//                                    }
//                                }

                                $(this).find('input[name="isDepartmentHs"]').val(row.isDepartmentHs);
                                $(this).find('input[name="isProjectHs"]').val(row.isProjectHs);
                                $(this).find('input[name="isExpecoHs"]').val(row.isExpecoHs);
                                $(this).find('input[name="isExpfuncHs"]').val(row.isExpfuncHs);
                                $(this).find('input[name="isDepproHs"]').val(row.isDepproHs);

                                // preKmObj.isWlHs = data.isWlHs;
                                $(this).next().find('input').removeAttr('disabled');
                                $(this).find('input[name="j1"]').attr("readonly", "readonly");
                                $(this).find('input[name="d1"]').attr("readonly", "readonly");
                                $(this).find('input[name="j2"]').attr("readonly", "readonly");
                                $(this).find('input[name="d2"]').attr("readonly", "readonly");
                            }
                        });

                        totalCalc();
                    }
                });
            } else {
                if(!!kjqj){

                } else {
                    kjqj = new Date().getMonth() + 1;
                }
                $("#kjqj_select").lrselectSet(kjqj);
                page.InitialPage();
            }
            page.propGrid($grid);
            //默认不可编辑
            if (edit == 0) {
                $("#form1 input").attr("readonly", "readonly");
            } else {
                $("#form1 input").removeAttr("disabled");
                $("#gridTable").find('[role=row]').each(function (i) {
                    var extStr = $(this).find('td:eq(2)').html();
                    var extInfo = null;
                    if (extStr) {
                        extInfo = JSON.parse(extStr);
                    }
                    if (extInfo&&extInfo.length>0) {
                        $(this).find('input[name="j"]').attr("readonly", "readonly");
                        $(this).find('input[name="d"]').attr("readonly", "readonly");
                    }
                });
            }
            if(!!keyValue && !!flxh) {
                $("#gridTable").find('[role=row][id="' + flxh + '"]').each(function (i,item) {
                    //$(item).addClass("selectrow");
                    $(item).click();
                });

            }
        },

        propGrid: function ($grid) {
            $grid.find('.disabled').attr("disabled", "disabled");

            //贷失去焦点
            $('#gridTable input[name="d"]').blur(function () {
                if (!!$(this).val()) {
                    $(this).parents('[role=row]').find('input[name="j"]').val('');
                }
                totalCalc();
            });
            //回车跳转事件
            $('input[name="zy"]').keydown(function (event) {
                if (13 == event.keyCode) {
                    if (!!$(this).val()) {
                        $(this).parents('[role=row]').find('input[name="kjkmName"]').focus();
                    }
                }
            });
            $('#gridTable input[name="j"]').keydown(function (event) {
                if (13 == event.keyCode) {
                    $(this).parents('[role=row]').find('input[name="d"]').focus();
                    //totalCalc();
                }
            });
            $('#gridTable input[name="d"]').keydown(function (event) {
                if (13 == event.keyCode) {
                    if (!!$(this).val() || !!$(this).parents('[role=row]').find('input[name="j"]').val()) {
                        $(this).parents('[role=row]').next().find('input[name="zy"]').focus();
                        //totalCalc();

                        var nextZy = $(this).parents('[role=row]').next().find('input[name="zy"]').val();
                        if (!nextZy) {
                            var currentZy = $(this).parents('[role=row]').find('input[name="zy"]').val();
                            $(this).parents('[role=row]').next().find('input[name="zy"]').val(currentZy);
                        }
                    }
                }
            });
        },

        propGridExt: function () {
            var $grid_ext = $("#gridTable_ext");

            //借失去焦点
            $('#gridTable_ext input[name="j"]').blur(function () {
                if (!!$(this).val()) {
                    $(this).parents('[role=row]').find('input[name="d"]').val('');
                }
                totalCalcExt();
            });
            //贷失去焦点
            $('#gridTable_ext input[name="d"]').blur(function () {
                if (!!$(this).val()) {
                    $(this).parents('[role=row]').find('input[name="j"]').val('');
                }
                totalCalcExt();
            });
            //回车跳转事件
            $('#gridTable_ext input[name="j"]').keydown(function (event) {
                if (13 == event.keyCode) {
                    $(this).parents('[role=row]').find('input[name="d"]').focus();
                    //totalCalc();
                }
            });
            $('#gridTable_ext input[name="d"]').keydown(function (event) {
                if (13 == event.keyCode) {
                    if (!!$(this).val() || !!$(this).parents('[role=row]').find('input[name="j"]').val()) {
                        //totalCalc();
                    }
                    $(this).blur();
                }
            });
        },

        //临时存储extGrid的数据
        saveExtGridData: function () {
            if(preRowIndex == -1){
                return;
            }
            var extEntryJson = [];
            var columnName = "";

            if (preKmObj.isDepartmentHs == 1) {
                columnName = "departmentName"
            } else if (preKmObj.isProjectHs == 1) {
                columnName = "projectName"
            } else if (preKmObj.isExpecoHs == 1) {
                columnName = "expecoName"
            } else if (preKmObj.isExpfuncHs == 1) {
                columnName = "expfuncName"
            } else if (preKmObj.isDepproHs == 1) {
                columnName = "depproName"
            }
            if (columnName != "") {
                var i = 1;
                $("#gridTable_ext").find('[role=row]').each(function (i) {
                    if (!!$(this).find('input[name="' + columnName + '"]').val()) {
                        extEntryJson.push({
                            extxh: i++,
                            extid: $(this).find('input[name="extid"]').val(),
                            departmentName: $(this).find('input[name="departmentName"]').val(),
                            projectName: $(this).find('input[name="projectName"]').val(),
                            expecoName: $(this).find('input[name="expecoName"]').val(),
                            expfuncName: $(this).find('input[name="expfuncName"]').val(),
                            depproName: $(this).find('input[name="depproName"]').val(),
                            j: $(this).find('input[name="j"]').val() == "" ? 0 : $.unformatMoney($(this).find('input[name="j"]').val()),
                            d: $(this).find('input[name="d"]').val() == "" ? 0 : $.unformatMoney($(this).find('input[name="d"]').val()),
                            departmentCode: $(this).find('input[name="departmentCode"]').val(),
                            projectCode: $(this).find('input[name="projectCode"]').val(),
                            expecoCode: $(this).find('input[name="expecoCode"]').val(),
                            expfuncCode: $(this).find('input[name="expfuncCode"]').val(),
                            depproCode: $(this).find('input[name="depproCode"]').val()
                        });
                    }
                });
                var extList = JSON.stringify(extEntryJson);
                $("#gridTable").jqGrid('setRowData', preRowIndex, {extList: extList});
            }
        },

    }

    page.init();
}

//分录合计
function totalCalc() {
    var Total_J = 0.00, Total_D = 0.00;
    $("#gridTable").find("tbody tr").each(function (i) {
        var j = $(this).find('td:eq(13)').find('input').val();
        if (j != "" && j != undefined) {
            if (j.indexOf(",") > 0) { //处理千分位
                j = j.replace(/\,/g, "");
            }
            //Total_J += Number(j);
            Total_J = calc.add(Total_J, Number(j));
        }
        var d = $(this).find('td:eq(14)').find('input').val();
        if (d != "" && d != undefined) {
            if (d.indexOf(",") > 0) { //处理千分位
                d = d.replace(/\,/g, "");
            }
            //Total_D += Number(d);
            Total_D = calc.add(Total_D, Number(d));
        }
    });
    $("#TotalJ1").text($.formatMoney(Total_J, 2));
    $("#TotalD1").text($.formatMoney(Total_D, 2));
    $("#TotalJ2").text($.formatMoney(Total_J, 2));
    $("#TotalD2").text($.formatMoney(Total_D, 2));
}

//ext合计
function totalCalcExt() {
    var $grid_ext = $("#gridTable_ext");
    var TotalExtJ = 0.00, TotalExtD = 0.00;
    var TotalJ = 0.00, TotalD = 0.00;
    $grid_ext.find("tbody tr").each(function (i) {
        var j = $(this).find('td:eq(7)').find('input').val();
        var d = $(this).find('td:eq(8)').find('input').val();
        if (j != "" && j != undefined) {
            if (j.indexOf(",") > 0) { //处理千分位
                j = j.replace(/\,/g, "");
            }
            //TotalExtJ += Number(j);
            TotalExtJ = calc.add(TotalExtJ, Number(j));
        }
        if (d != "" && d != undefined) {
            if (d.indexOf(",") > 0) { //处理千分位
                d = d.replace(/\,/g, "");
            }
            //TotalExtD += Number(d);
            TotalExtD = calc.add(TotalExtD, Number(d));
        }
    });
    $("#TotalExtJ").text($.formatMoney(TotalExtJ, 2));
    $("#TotalExtD").text($.formatMoney(TotalExtD, 2));
}

//切换凭证日期获取当前最大凭证号
function setDatePickerValue(newDate) {
    if (!!keyValue) {
        return;
    }
    var pzlxCode = $("#pzlxCode").attr("data-value");
    $.ajax({
        url: config.base_server() + 'glvous/getPzh?companyId=' + companyId + '&ztId=' + ztId + '&pzrq=' + newDate + '&pzlxCode=' + pzlxCode + '&access_token=' + config.getToken().access_token,
        type: "get",
        dataType: "json",
        async: false,
        success: function (result) {
            if (result != null) {
                $("#pzh").val(result.data);
            }
        }
    });
}

// 凭证打印
function btn_print() {
    var ids = keyValue;
    var hiprintTemplate = null;
    $.ajax({
        url: config.base_server() + 'printTempletes/findByCode?companyId=' + companyId + '&ztId=' + ztId + '&code=pz&access_token=' + config.getToken().access_token,
        type: "get",
        dataType: "json",
        async: false,
        success: function (res) {
            if (res.resp_code == 200) {
                hiprintTemplate = new hiprint.PrintTemplate({
                    template: JSON.parse(res.data.templete),
                    settingContainer: '#PrintElementOptionSetting',
                    paginationContainer: '.hiprint-printPagination'
                });

                //hiprintTemplate.design('#hiprint-printTemplate');
                $.ajax({
                    url: config.base_server() + 'glvous/findByIds?ids=' + ids + '&access_token=' + config.getToken().access_token,
                    type: "get",
                    dataType: "json",
                    async: false,
                    success: function (res) {
                        if (res.resp_code == 200) {
                            var jsonData = [];

                            for (var i = 0; i < res.data.length; i++) {
                                var item = {};
                                var pzh = "(" + res.data[i].pzz + ")" + res.data[i].pzh;
                                item.pzh = pzh;
                                var pzrqArr = res.data[i].pzrq.split("-");
                                item.pzrq = pzrqArr[0] + "年" + pzrqArr[1] + "月" + pzrqArr[2] + "日";
                                item.zdy = res.data[i].zdy;
                                item.shy = res.data[i].shy;
                                item.jzy = res.data[i].jzy;
                                item.cwzg = res.data[i].cwzg;
                                item.ztName = res.data[i].ztName;
                                item.fj = res.data[i].fj;
                                item.total1 = "人民币"+res.data[i].total1;
                                item.total2 = $.formatMoney(res.data[i].total2, 2);
                                item.pzflList = res.data[i].pzflList;

                                for (var j = 0; j < item.pzflList.length; j++) {
                                    item.pzflList[j].j = $.formatMoney(item.pzflList[j].j, 2);
                                    item.pzflList[j].d = $.formatMoney(item.pzflList[j].d, 2);
                                    item.pzflList[j].ye = $.formatMoney(item.pzflList[j].ye, 2);
                                }

                                jsonData.push(item);
                            }
                            hiprintTemplate.resetPage();
                            // hiprintTemplate.print(jsonData);
                            $('#myModal .modal-body .prevViewDiv').html(hiprintTemplate.getHtml(jsonData));
                            $(".hiprint-printPaper div .hiprint-printElement-vline").each(function (i,item) {
                                var newHtml = $(this).prop("outerHTML")
                                    .replace("<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 24pt; left: 18pt; top: 699pt;\"></div>","<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 28pt; left: 18pt; top: 695pt;\"></div>")
                                    .replace("<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 24pt; left: 424.5pt; top: 699pt;\"></div>","<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 28pt; left: 424.5pt; top: 695pt;\"></div>")
                                    .replace("<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 24pt; left: 495.5pt; top: 699pt;\"></div>","<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 28pt; left: 495.5pt; top: 695pt;\"></div>")
                                    .replace("<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 24pt; left: 566.5pt; top: 699pt;\"></div>","<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 28pt; left: 566.5pt; top: 695pt;\"></div>")
                                    .replace("<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 24pt; left: 18pt; top: 699pt;\"></div>","<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 28pt; left: 18pt; top: 695pt;\"></div>");

                                $(this).prop("outerHTML",newHtml);
                            });

                            $('#myModal').modal('show');
                        }
                    }
                });
                $('#A4_printByHtml').click(function () {
                    hiprintTemplate.printByHtml($('#myModal .modal-body .prevViewDiv'));
                })
            }
        }
    });
}

//失去焦点转化为千分位
function toMoney(value, target) {
    if (value == "" || value.indexOf(",") > 0) {
        return;
    }

    $(target).val($.formatMoney(value, 2));
}

//光标进入，去除金额千分位，并去除小数后面多余的0
function toNumber(value, target) {
    if (value.indexOf(",") < 0) {
        $(target).select();
        return;
    }

    var oldMny = value.replace(/,/g, '');
    if (oldMny.indexOf(".") > 0) {
        oldMny = oldMny.replace(/0+?$/, "");//去除尾部多余的0
        oldMny = oldMny.replace(/[.]$/, "");//如果最后一位是.则去掉
    }
    $(target).val(oldMny);
    $(target).select();
}

//前单
function btn_prev() {
    var pzrq = $("#pzrq").val();
    var pzlxCode = $("#pzlxCode").attr("data-value");
    $.ajax({
        url: config.base_server() + 'glvous/pre?keyValue=' + keyValue + '&pzrq=' + pzrq + '&pzlxCode=' + pzlxCode + '&access_token=' + config.getToken().access_token,
        type: "get",
        dataType: "json",
        async: false,
        success: function (result) {
            if (result != null && result.data != null) {
                var src = config.webportal_server + '/pages/finance/pz/view.html?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&userId=' + userId + '&keyValue=' + result.data.pzid + '&access_token=' + config.getToken().access_token
                window.location = src;
                // $.currentIframe().att('src', src);
            }
        }
    });
}

//后单
function btn_next() {
    var pzrq = $("#pzrq").val();
    var pzlxCode = $("#pzlxCode").attr("data-value");
    $.ajax({
        url: config.base_server() + 'glvous/next?keyValue=' + keyValue + '&pzrq=' + pzrq + '&pzlxCode=' + pzlxCode + '&access_token=' + config.getToken().access_token,
        type: "get",
        dataType: "json",
        async: false,
        success: function (result) {
            if (result != null && result.data != null) {
                var src = config.webportal_server + '/pages/finance/pz/view.html?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&userId=' + userId + '&keyValue=' + result.data.pzid + '&access_token=' + config.getToken().access_token
                window.location = src;
                // $.currentIframe().att('src', src);
            }
        }
    });
}
